﻿using Microsoft.Xna.Framework;
using SomeGame.GUI.Widgets;
using SomeGame.GUI.Widgets.BlockWidgets;
using SomeGame.GUI.Widgets.Containers;
using SomeGame.GUI.Widgets.Events.Click;
using SomeGame.GUI.Widgets.InlineWidgets;
using SomeGame.Input;

namespace SomeGame.GUI.Screens {

    public class AreYouSureScreen : Screen, IClickSubscriber {

        public AreYouSureScreen() {
            Name = ScreenManager.ARE_YOU_SURE_SCREEN;
            RootContainer = new RootContainer(this, GameEngine.Blank, GameEngine.GameBounds, new Color(20, 20, 20, 20)) {
                ID = "AreYouSureScreen_RootContainer"
            };

            BlockContainer dialogBoxFrame = new BlockContainer(GameEngine.Blank, new Color(10, 10, 10)) {
                ID = "AreYouSureScreen_DialogBoxFrame",
                Width = 300,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Margin(100, 0, 0, 0),
                Padding = new Padding(10)
            };
            RootContainer.AddWidget(dialogBoxFrame);

            BlockContainer dialogBoxBody = new BlockContainer(GameEngine.Blank, new Color(150, 90, 50)) {
                ID = "AreYouSureScreen_DialogBoxBody",
                Height = 167
            };
            dialogBoxFrame.AddWidget(dialogBoxBody);

            dialogBoxBody.AddWidget(new Label(GameEngine.Blank,
                200,
                50,
                Color.Transparent,
                GameEngine.Consolas16,
                Color.AntiqueWhite,
                "Are you sure?") {
                    ID = "AreYouSureScreen_Label",
                    Margin = new Margin(30, 0, 0, 0),
                    HorizontalAlignment = HorizontalAlignment.Center
                });

            dialogBoxBody.AddWidget(new Break {
                ID = "AreYouSureScreen_Break"
            });

            InlineContainer buttonBar = new InlineContainer(GameEngine.Blank, Color.Transparent) {
                ID = "AreYouSureScreen_ButtonBar",
                Margin = new Margin(40, 10),
                HorizontalAlignment = HorizontalAlignment.Right
            };
            dialogBoxBody.AddWidget(buttonBar);

            Button yesButton = new Button(GameEngine.Blank,
                60,
                40,
                new Color(39, 68, 127),
                GameEngine.Consolas16,
                Color.AntiqueWhite,
                "Yes") {
                    ID = "AreYouSureScreen_YesButton",
                    HoverColor = new Color(60, 106, 196)
                };
            yesButton.AddSubscriber(this);
            buttonBar.AddWidget(yesButton);

            Button noButton = new Button(GameEngine.Blank,
                60,
                40,
                new Color(39, 68, 127),
                GameEngine.Consolas16,
                Color.AntiqueWhite,
                "No") {
                    ID = "AreYouSureScreen_NoButton",
                    Margin = new Margin(0, 0, 0, 10),
                    HoverColor = new Color(60, 106, 196)
                };
            noButton.AddSubscriber(this);
            buttonBar.AddWidget(noButton);

            RootContainer.Layout();
        }

        public void OnClick(ClickEventArgs clickEventArgs) {
            switch (((Widget) clickEventArgs.ClickPublisher).ID) {
                case "AreYouSureScreen_YesButton":
                    InputActions.Exit();
                    break;
                case "AreYouSureScreen_NoButton":
                    ScreenManager.DeactivateScreen(Name);
                    break;
            }
        }

    }

}